<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client;

class Release
{
    public static function release(\Composer\Script\Event $event)
    {
        $arguments = $event->getArguments();
        if(count($arguments) <= 1) {
            echo "Missing ChangeLog";
        } else {
            self::updateChangelogFile($arguments[0], $arguments[1]);
            self::changeVersionInCode($arguments[0]);
        }
    }
    private static function updateChangelogFile($version, $changeLog)
    {
        $content = preg_replace("/# CHANGELOG/", "# CHANGELOG\n\n" . "## " . $version . " - " . date("Y-m-d") . self::log($changeLog), self::getChangeLogContent());
        file_put_contents(self::getChangeLogFile(), $content);
    }
    private static function log($changeLog)
    {
        $logs = explode("|", $changeLog);
        $string = "\n";
        foreach ($logs as $log) {
            if($log) {
                $string .= "- " . $log . "." . "\n";
            }
        }
        return $string;
    }
    private static function getChangeLogContent()
    {
        return file_get_contents(self::getChangeLogFile());
    }
    private static function getChangeLogFile()
    {
        return __DIR__ . "/../CHANGELOG.md";
    }
    private static function changeVersionInCode($version)
    {
        $content = preg_replace("/const VERSION = \\'(.*)\\';/", "const VERSION = '" . $version . "';", self::getCodeContent());
        file_put_contents(self::getCodeFile(), $content);
    }
    private static function getCodeContent()
    {
        return file_get_contents(self::getCodeFile());
    }
    private static function getCodeFile()
    {
        return __DIR__ . "/AlibabaCloud.php";
    }
}

?>